package com.tencent.ncnnyolox.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.tencent.ncnnyolox.R;
import com.tencent.ncnnyolox.basemodule.base.BaseDialog;
import com.tencent.ncnnyolox.basemodule.view.CommonEditDialog;
import com.tencent.ncnnyolox.net.ApiViewModel;
import com.tencent.ncnnyolox.net.bean.ChatPhraseBean;
import com.tencent.ncnnyolox.net.bean.ChatPhraseUpdateDTO;
import com.tencent.ncnnyolox.net.bean.CommonWordBean;
import com.tencent.ncnnyolox.net.bean.PhraseLabelBean;
import com.yd.basemodule.base.bean.BaseResult;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *     author : yh
 *     e-mail : xxx@xx
 *     time   : 2023/12/15
 *     desc   :
 * </pre>
 */
public class CommonAdapter extends RecyclerView.Adapter<CommonAdapter.ViewHolder> {

    private List<CommonWordBean> list = new ArrayList<>();
    private LifecycleOwner lifecycleOwner;
    private Context context;

    class ViewHolder extends RecyclerView.ViewHolder {


        TextView tvCommonLabel;
        RecyclerView  recycle;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvCommonLabel = itemView.findViewById(R.id.tv_common_label);
            recycle=itemView.findViewById(R.id.recycle_changyong);
        }
    }

    private ClickItemListener listener;
   public interface ClickItemListener{
        void onClick(String content);
    }

    public CommonAdapter(Context context, LifecycleOwner viewModel) {
        this.context = context;
        this.lifecycleOwner = viewModel;
    }

    public void setDate(List<CommonWordBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void setClickItemListener( ClickItemListener listener){
        this.listener=listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_item, parent, false);
        return new CommonAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvCommonLabel.setText(list.get(position).getLabelName());

        CommonCYAdapter adapter=new CommonCYAdapter(context,lifecycleOwner);
        holder.recycle.setLayoutManager(new LinearLayoutManager(context));
        adapter.setDate(list.get(position).getChatPhraseList());
        holder.recycle.setAdapter(adapter);
        adapter.CommonCYAdapterSetOnClickListener(new CommonCYAdapter.CommonCYAdapterClickItemListener() {
            @Override
            public void onClick(String content) {
                listener.onClick(content);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


}
